//
//  SNHomePageTableViewCell.m
//  project
//
//  Created by 黄建华 on 2017/11/24.
//  Copyright © 2017年 黄建华. All rights reserved.
//

#import "SNHomePageTableViewCell.h"

@implementation SNHomePageTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    
    return self;
}

- (void)createView {
    _shadowView = [[SNShadowView alloc] init];
    [self addSubview:_shadowView];
    
    _button = [[UIButton alloc] init];
    [_shadowView addSubview:_button];
    
    _typeImageView = [[UIImageView alloc] init];
    [_button addSubview:_typeImageView];
    
    _valueLabel = [[SNCustomLabel alloc] init];
    [_button addSubview:_valueLabel];
    
    _detailLabel = [[SNCustomLabel alloc] init];
    [_button addSubview:_detailLabel];
    
    _typeLabel = [[SNCustomLabel alloc] init];
    [_button addSubview:_typeLabel];
    
    //

    _shadowView2 = [[SNShadowView alloc] init];
    [self addSubview:_shadowView2];
    
    _button2 = [[UIButton alloc] init];
    [_shadowView2 addSubview:_button2];
    
    _typeImageView2 = [[UIImageView alloc] init];
    [_button2 addSubview:_typeImageView2];
    
    _valueLabel2 = [[SNCustomLabel alloc] init];
    [_button2 addSubview:_valueLabel2];
    
    _detailLabel2 = [[SNCustomLabel alloc] init];
    [_button2 addSubview:_detailLabel2];
    
    _typeLabel2 = [[SNCustomLabel alloc] init];
    [_button2 addSubview:_typeLabel2];
}

- (void)updateMainCellLeft:(NSArray *)leftArray {
    CGFloat rowwidth = HHHWIDTH/2;
    CGFloat space    = FitW(13);
    
    _shadowView.frame             = SNFRAME(space, space, rowwidth - 1.5* space, rowwidth - 1.5* space);
    _shadowView.layer.borderWidth = 0.5;
    _shadowView.layer.borderColor = SNCOLORGRAYLINE.CGColor;
    
    _button.backgroundColor = [UIColor clearColor];
    _button.frame           = CGRectMake(0, 0, _shadowView.width, _shadowView.height);
    _button.tag             = [[leftArray lastObject] integerValue];
    
    _typeImageView.frame = SNFRAME( (1-0.43)/2 * _button.width, FitW(20), _button.width /2.3, _button.width /2.3);
    _typeImageView.image = [leftArray objectAtIndex:0];
    
    _valueLabel.frame         = SNFRAME(0, _button.width /3 +FitW(45), _button.width, FitW(22));
    _valueLabel.font          = SNFONT(FitFont(20.0));
    _valueLabel.textAlignment = NSTextAlignmentCenter;
    _valueLabel.text          = [leftArray objectAtIndex:1];
    
    _detailLabel.frame         = SNFRAME(0, _button.width /3 + FitW(30 +25), _button.width, FitW(40));
    _detailLabel.font          = SNSFONT(FitFont(11.0));
    _detailLabel.textColor     = [UIColor colorFromHex:0x767676];
    _detailLabel.text          = [leftArray objectAtIndex:2];
    _detailLabel.numberOfLines = 2;
    
    _typeLabel.frame         = SNFRAME(0, _button.height - FitW(30), _button.width, FitW(20));
    _typeLabel.textAlignment = NSTextAlignmentCenter;
    _typeLabel.font          = SNFONT(FitFont(14.0));
    _typeLabel.text          = [leftArray objectAtIndex:3];
    
    if (_button.tag == 0) {
        [_valueLabel setAttributedText:[SN_PublicClass label1With:_valueLabel.text withFontsize:15.0 withChangeText1:SN_Text(@"h") withChangeText2:SN_Text(@"mins")]];
    }
    if (_button.tag == 2) {
        [_valueLabel setAttributedText:[SN_PublicClass label1With:_valueLabel.text withFontsize:15.0 withChangeText1:@"" withChangeText2:@"bpm"]];
    }
    if (_button.tag == 4) {
        [_valueLabel setAttributedText:[SN_PublicClass label1With:_valueLabel.text withFontsize:15.0 withChangeText1:@"" withChangeText2:@"mmhg"]];
    }
}

- (void)updateMainCellRight:(NSArray *)rightArray {
    CGFloat rowwidth = HHHWIDTH/2;
    CGFloat space    = FitW(13);
    _shadowView2.frame             = SNFRAME(space*0.5 +rowwidth, space, rowwidth - 1.5* space, rowwidth - 1.5* space);
    _shadowView2.layer.borderWidth = 0.5;
    _shadowView2.layer.borderColor = SNCOLORGRAYLINE.CGColor;
    
    _button2.backgroundColor = [UIColor clearColor];
    _button2.frame           = CGRectMake(0, 0, _shadowView2.width, _shadowView2.height);
    _button2.tag             = [[rightArray lastObject] integerValue];
    
    if (_button2.tag == 1) {
        _typeImageView2.frame = SNFRAME(_button.width /3, FitW(20)+ 10, _button.width /3, _button.width /3);
        _typeImageView2.image = [rightArray objectAtIndex:0];
    } else {
        _typeImageView2.frame = SNFRAME( (1-0.43)/2 * _button.width, FitW(20), _button.width /2.3, _button.width /2.3);
        _typeImageView2.image = [rightArray objectAtIndex:0];
    }
    
    _valueLabel2.frame         = SNFRAME(0, _button2.width /3 + FitW(45), _button2.width, FitW(22));
    _valueLabel2.font          = SNFONT(FitFont(20.0));
    _valueLabel2.textAlignment = NSTextAlignmentCenter;
    _valueLabel2.text          = [rightArray objectAtIndex:1];
    
    _detailLabel2.frame         = SNFRAME(0, _button2.width /3 + FitW(30+25), _button2.width, FitW(40));
    _detailLabel2.font          = SNSFONT(FitFont(11.0));
    _detailLabel2.textColor     = [UIColor colorFromHex:0x767676];
    _detailLabel2.text          = [rightArray objectAtIndex:2];
    _detailLabel2.numberOfLines = 2;
    
    _typeLabel2.frame         = SNFRAME(0, _button2.height - FitW(30), _button2.width, FitW(20));
    _typeLabel2.textAlignment = NSTextAlignmentCenter;
    _typeLabel2.font          = SNFONT(FitFont(14.0));
    _typeLabel2.text          = [rightArray objectAtIndex:3];
}

- (int)getTypeWithArray:(NSArray *)array {
    int      type        = 0;
    NSString *typeString = [array lastObject];
    
    NSLog(@"typeString>>>>>%@", typeString);
    
    if ([typeString isEqualToString:SN_Text(@"睡眠记录")]) {
        type = 0;
    }
    if ([typeString isEqualToString:SN_Text(@"我的体检")]) {
        type = 1;
    }
    if ([typeString isEqualToString:SN_Text(@"心率记录")]) {
        type = 2;
    }
    if ([typeString isEqualToString:SN_Text(@"血氧记录")]) {
        type = 3;
    }
    if ([typeString isEqualToString:SN_Text(@"血压记录")]) {
        type = 4;
    }
    return type;
}

@end

